import {actionTypes} from './index'
import {fromJS} from 'immutable'
import en_US from '@/locale/en_US'
import zh_CN from '@/locale/zh_CN'

const getLocaleMessage = (val) => {
    const locale = val || navigator.language.split('-')[0]
    let localeMessage
    switch (locale) {
        case 'en':
            localeMessage = en_US
            break;
        case 'zh':
            localeMessage = zh_CN
            break;
        default:
            localeMessage = en_US
    }
    return {
        locale,
        localeMessage
    }
}
export const changeLocale = (value) => {
    const localeObj = getLocaleMessage(value)
    console.log(localeObj)
    return {
        type: actionTypes.CHANGE_LOCALE,
        value: fromJS(localeObj)
    }
}
